package com.yxjme.opengl_0;

import android.content.Context;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;

public class Util {



    /**
     * @param context
     * @return
     */
    public static String readTextFileFromResource(Context context, String n) {
        StringBuffer stringBuffer = new StringBuffer();
        try {
            InputStream is = context.getResources().getAssets().open(n);
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is));
            String result;
            while ((result=bufferedReader.readLine())!=null){
                stringBuffer.append(result).append("\n");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return stringBuffer.toString();
    }


    /**
     * @param f
     *
     * @return
     */
    public static FloatBuffer toFloatBuffer(float[] f){
        int BYTES_PER_FLOAT = 4;
        FloatBuffer verticeData = ByteBuffer.allocateDirect(f.length * BYTES_PER_FLOAT)
                .order(ByteOrder.nativeOrder())
                .asFloatBuffer()
                .put(f);
        verticeData.position(0);
        return verticeData;
    }



}
